persistence.setNamespace("peiwan_promoter");
var peiwanWeixin = angular.module('peiwan_weixin', []);
peiwanWeixin.controller('RegisterCtrl', [
		"$scope",
		function(s) {
			s.years = (function() {
				var arr = [];
				for (var i = 1950; i < 1990; i++) {
					arr.push(i)
				}
				return arr;
			})();
			s.years2 = (function() {
				var arr = [];
				for (var i = 1991; i < 2016; i++) {
					arr.push(i)
				}
				return arr;
			})();
			s.months = (function() {
				var arr = [];
				for (var i = 1; i < 13; i++) {
					arr.push(i)
				}
				return arr;
			})();
			s.days = (function() {
				var arr = [];
				for (var i = 1; i < 32; i++) {
					arr.push(i)
				}
				return arr;
			})();
			s.oldCancel = function() {
				$("#old_modal").css("display", "none");
			};
			s.oldOk = function() {
				$("#old_modal").css("display", "none");
				var year = $("#year_select").val();
				var month = $("#month_select").val();
				var day = $("#day_select").val();
				$("#birth").val(year + "/" + month + "/" + day);
			};
			s.chooseBirthClicked = function() {
				$("#old_modal").css("display", "block");
			};
			s.ok = function() {
				var headUrl = "http://chuangjike-img-real.b0.upaiyun.com/icons/xiangji.png";
				var nickname = $("#nickname").val();
				var gender = $("#gender").val();
				var birth = $("#birth").val();
				if (nickname == "") {
					swal({
						title : "",
						text : "请填写昵称！",
						type : "error"
					});
					return;
				}
				if (gender == "选择后不可更换") {
					swal({
						title : "",
						text : "请选择性别！",
						type : "error"
					});
					return;
				}
				if (birth == "选择后不可更换") {
					swal({
						title : "",
						text : "请选择生日！",
						type : "error"
					});
					return;
				}
				persistence.put("headUrl", headUrl);
				persistence.put("nickname", nickname);
				persistence.put("birth", birth);
				location.href = "register2.html";
			};
			s.chooseGender = function() {
				$("#gender_modal").show();
			};
			s.genderModalCancel = function() {
				$("#gender_modal").css("display", "none");
			};
			s.gender = function(gender) {
				persistence.put("gender", gender);
				$("#gender").val(gender == 0 ? "男" : "女");
				$("#gender_modal").css("display", "none");
			};
		} ]);
